-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix crash related to useEffect returning a value instead of a function #78708
Conversation
I'm merging to resolve the page crash asap. |
This PR does not affect the size of JS and CSS bundles shipped to the user's browser. Generated by performance advisor bot at iscalypsofastyet.com. |
I did some searching around, and the types are supposed to handle this situation. However, the types don't forbid callbacks typed as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good FWIW, thanks for the swift fixes 👍
Wow. Didn't know about this. @noahtallen, thanks for the quick fix! FYI -> @Automattic/caribou |
Yeah, neither did I, to be honest! I'll p2 about it today. |
Related to: #77046
Proposed Changes
Resolves https://a8c.sentry.io/issues/4279026430/?project=6313676
Sentry detected a page crash in this scenario:
After testing this locally, I found warnings in the console about useEffect returning a value. This also lead me to a Stackoverflow post: https://stackoverflow.com/questions/74265321/uncaught-typeerror-destroy-is-not-a-function-error-in-react
The issue is that when useEffect's callback returns a value, React will try to call it as a function. (This function can be used to destroy or unsubscribe from things set up in the effect.)
When that value is not a function, the page crashes.
So I went through several useEffect calls on the related pages and updated several inline effect calls to not return values. We had several which were doing like
useEffect( () => ifCheck && doSomething() )
. These can return booleans, which causes the crash. This is probably new behavior in React 18.I fixed this just be wrapping these callbacks in brackets (e.g.
useEffect( () => { ifCheck && doSomething() } )
), which should be functionally the same.We will also need to add a linter rule and check this doesn't happen elsewhere.
Testing Instructions
Follow the above bug-reproduction steps and check that there is no crash.